<template>
    <h2 style="text-align: center;">添加等级信息</h2>
    <table border="1" class="table table-bordered">
        <tbody>
            <tr>
                <th>等级名称</th>
                <th>
                    <input type="text " placeholder="请输入等级名称" v-model="Info.MemberRank_Name" />
                </th>
            </tr>

            <tr>
                <th>等级状态</th>
                <th>
                    <input type="radio" :value="true" checked v-model="Info.MemberRank_State"/>启用
                    <input type="radio" :value="false"  v-model="Info.MemberRank_State"/>禁用
                </th>
            </tr>

            <tr>
                <th>权益名称</th>
                <th>
                    <select v-model="Info.MemberRight_Id">
                        <option :value="-1">请选择</option>
                        <option v-for="item in InfoRight" :value="item.MemberRight_Id">{{ item.MemberRight_Name }}</option>
                    </select>
                </th>
            </tr>

            <tr>
                <th colspan="2" style="text-align: center;">
                    <input type="button" value="添加等级信息" class="btn btn-success" @click="AddMemberRank"  style="margin-right: 10px;"/>
                    <a href="/ShowMemberRank">返回列表</a>
                 </th>
            </tr>
        </tbody>
    </table>
</template>



<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import { useRouter } from 'vue-router';

    const router=useRouter();
    const Info=ref({
        MemberRank_Name: "",
        MemberRank_State: true,
        MemberRight_Id: -1
    })
    //权益信息
    const InfoRight=ref([{
        MemberRight_Id: 0,
        MemberRight_Name: "",
    }])
    onMounted(()=>{
        GetMemberRights();//获取权益
    })
    //获取权益
    const GetMemberRights=()=>{
        axios.get("https://localhost:44390/api/MemberRank/GetMemberRights")
        .then(res=>{
            InfoRight.value=res.data
        })
    }
    //添加等级
    const AddMemberRank=()=>{
        axios.post("https://localhost:44390/api/MemberRank/AddMemberRank",Info.value)
        .then(res=>{
            if(res.data>0)
            {
                alert('等级信息添加成功');
                router.push("/ShowMemberRank");
            }
            else
            {
                alert('等级信息添加失败');
            }
        })
    }
</script>
